package com.corpgovernment.travelstandard.utils;

import cn.hutool.core.lang.Pair;
import cn.hutool.core.util.ObjectUtil;
import com.corpgovernment.api.travelstandard.enums.*;
import com.corpgovernment.api.travelstandard.vo.*;
import com.corpgovernment.api.travelstandard.vo.car.CarCityControl;
import com.corpgovernment.api.travelstandard.vo.car.CarCityControlVo;
import com.corpgovernment.api.travelstandard.vo.car.CarCityVo;
import com.corpgovernment.api.travelstandard.vo.car.ModelControl;
import com.corpgovernment.api.travelstandard.vo.car.PriceControl;
import com.corpgovernment.api.travelstandard.vo.car.*;
import com.corpgovernment.api.travelstandard.vo.intlflight.IntlFlightManageVo;
import com.corpgovernment.api.travelstandard.vo.intlflight.MbTravelstandIntlFlightVo;
import com.corpgovernment.common.currency.CurrencyConversionUtil;
import com.corpgovernment.common.currency.bo.CurrencyExchangeBO;
import com.corpgovernment.common.utils.DateUtil;
import com.corpgovernment.organization.constant.CommonConst;
import com.corpgovernment.travelstandard.entity.db.*;
import com.corpgovernment.supplier.constant.CommonConstant;
import com.corpgovernment.travelstandard.entity.db.MbTravelStandCarAddress;
import com.corpgovernment.travelstandard.entity.db.MbTravelStandCarCity;
import com.corpgovernment.travelstandard.entity.db.MbTravelstandCarDatetime;
import com.corpgovernment.travelstandard.entity.db.MbTravelstandReasonCode;
import com.ctrip.corp.obt.generic.utils.CollectionUtils;
import com.ctrip.corp.obt.generic.utils.StringUtils;
import com.corpgovernment.supplier.constant.CommonConstant;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.*;

/**
 * @author zbz
 * 特定bean相互转换
 */
@Slf4j
public class BeanConverUtil {

    /**
     * 将MbTravelstandFlightVo转化为FlightTravelStandardManageVo
     */
    public static FlightTravelStandardManageVo travelstandFlightVoToFlightTravelStandardManageVo(
        MbTravelstandFlightVo travelstandFlightVo,
        List<TravelStandardPostVo> travelStandardPostVos,
        List<MbTravelstandReasonCodeVo> reasonCodeVos,
        List<MbTravelstandFlightTimeVo> travelstandFlightTimeVos,
        List<MbTravelstandFlightCabinVo> standFlightCabinVos
    ) {
        if (travelstandFlightVo != null) {
            Map<String, List<Node>> dealReasonCodeVos = groupReasonCodeByType(reasonCodeVos);
            FlightTravelStandardManageVo flightTravelStandardManageVo = new FlightTravelStandardManageVo();
            flightTravelStandardManageVo.setOrgId(travelstandFlightVo.getOrgId());
            flightTravelStandardManageVo.setTitle(travelstandFlightVo.getName());
            flightTravelStandardManageVo.setId(String.valueOf(travelstandFlightVo.getId()));
            flightTravelStandardManageVo.setProductSwitch(travelstandFlightVo.getProductSwitch());
            StringBuilder scopeIds = new StringBuilder("");
            if (travelStandardPostVos != null) {
                int i = 1;
                for (TravelStandardPostVo travelStandardPostVo : travelStandardPostVos) {
                    scopeIds.append(travelStandardPostVo.getPostid());
                    if (i < travelStandardPostVos.size()) {
                        scopeIds.append(",");
                    }
                    i++;
                }
            }
            flightTravelStandardManageVo.setJobScopeId(scopeIds.toString());
            ClassDiscountControl classDiscountControl = new ClassDiscountControl();
            classDiscountControl.setClassDiscountChoose(travelstandFlightVo.getClassDiscountSwitch());
            classDiscountControl.setClassDiscountRcSet(travelstandFlightVo.getClassDiscountControlType());
            classDiscountControl.setClassDiscountRcList(dealReasonCodeVos.get(ReasonCodeTypeEnum.FC.getCode()));
            //舱等控制
            ClassSpace classSpace = new ClassSpace();
            //舱等（只有一个，前台无法多选）
            if(StringUtils.isNotBlank(travelstandFlightVo.getClassClass())) {
                classSpace.setClassCheckList(ClazzEnum.getCheckedNodeByCode(travelstandFlightVo.getClassClass()));
            }
            if(CollectionUtils.isNotEmpty(standFlightCabinVos)) {
                List<ClassSpace.ClassCheckNew> classCheckNewList = new ArrayList<>();
                List<String> shieldedList = new ArrayList<>();
                for(MbTravelstandFlightCabinVo flightCabinVo:standFlightCabinVos) {
                    if(StringUtils.endsWithIgnoreCase(CommonConstant.T, flightCabinVo.getCabinType())) {
                        ClassSpace.ClassCheckNew classCheckNew = new ClassSpace.ClassCheckNew();
                        classCheckNew.setClassCode(flightCabinVo.getClassCode());
                        classCheckNew.setClassName(ClazzEnum.getEnumByCode(flightCabinVo.getClassCode()).getName());
                        classCheckNew.setDurationType(flightCabinVo.getFlightDurationType());
                        classCheckNew.setDurationNum(flightCabinVo.getFlightDurationNum());
                        classCheckNewList.add(classCheckNew);
                    } else {
                        shieldedList.add(flightCabinVo.getClassCode());
                    }
                }
                classSpace.setClassCheckNewList(classCheckNewList);
                classSpace.setClassShieldedList(shieldedList);
            } else if(StringUtils.isNotBlank(travelstandFlightVo.getClassClass())) {
                List<ClazzEnum> clazzEnums = ClazzEnum.getLowerClazzEnumThanCode(travelstandFlightVo.getClassClass());
                List<ClassSpace.ClassCheckNew> classCheckNewList = new ArrayList<>();
                for (ClazzEnum clazzEnum : clazzEnums) {
                    ClassSpace.ClassCheckNew classCheckNew = new ClassSpace.ClassCheckNew();
                    classCheckNew.setClassCode(clazzEnum.getCode());
                    classCheckNew.setClassName(clazzEnum.getName());
                    classCheckNew.setDurationType(CommonConstant.F);
                    classCheckNew.setDurationNum(0);
                    classCheckNewList.add(classCheckNew);
                }
                classSpace.setClassCheckNewList(classCheckNewList);
            }
            //折扣管理
            classDiscountControl.setClassSpace(classSpace);
            Discount discount = new Discount();
            discount.setDiscountCheck(travelstandFlightVo.getDiscountClass());
            discount.setDiscountCheckList(ClazzEnum.getCheckedNodeByCode(""));
            discount.setDiscountNum(travelstandFlightVo.getDiscountNum().setScale(1, RoundingMode.HALF_UP).toString());
            classDiscountControl.setDiscount(discount);
            flightTravelStandardManageVo.setClassDiscountControl(classDiscountControl);
            //低价管控
            LowPriceDomAirTicket lowPriceDomAirTicket = new LowPriceDomAirTicket();
            lowPriceDomAirTicket.setStatus(travelstandFlightVo.getLowpriceSwitch());
            if (travelstandFlightVo.getLowpriceTimeOption() != null) {
                String lowPriceDomAirTicketTimeOptionsHour = new DecimalFormat("00").format(travelstandFlightVo.getLowpriceTimeOption() / 60);
                lowPriceDomAirTicket.setLowPriceDomAirTicketTimeOptionsHour(lowPriceDomAirTicketTimeOptionsHour);
                String lowPriceDomAirTicketTimeOptionsMinutes = new DecimalFormat("00").format(travelstandFlightVo.getLowpriceTimeOption() % 60);
                lowPriceDomAirTicket.setLowPriceDomAirTicketTimeOptionsMinutes(lowPriceDomAirTicketTimeOptionsMinutes);
            }
            lowPriceDomAirTicket.setLowPriceTimeStart(DateUtil.dateToHM(travelstandFlightVo.getLowpriceCompareTimeStart()));
            lowPriceDomAirTicket.setLowPriceTimeEnd(DateUtil.dateToHM(travelstandFlightVo.getLowpriceCompareTimeEnd()));
            lowPriceDomAirTicket.setLowPriceRcSet(travelstandFlightVo.getLowpriceControlType());
            lowPriceDomAirTicket.setLowPriceRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.FL.getCode()));
            lowPriceDomAirTicket.setAirportComparePrice(CommonConst.TRUE.equals(travelstandFlightVo.getAirportComparePrice()) ? CommonConst.TRUE : CommonConst.FALSE);
            lowPriceDomAirTicket.setTransferNeedComparePrice(CommonConst.TRUE.equals(travelstandFlightVo.getLowpriceTransferNeedCompare()) ? CommonConst.TRUE : CommonConst.FALSE);
            lowPriceDomAirTicket.setLowPriceFloatType(FlightSwitchEnum.LowPriceFloatTypeSwitch.B.getCode()
                    .equals(travelstandFlightVo.getLowpriceFloatType())
                    ? FlightSwitchEnum.LowPriceFloatTypeSwitch.B.getCode()
                    : FlightSwitchEnum.LowPriceFloatTypeSwitch.A.getCode());
            lowPriceDomAirTicket.setLowPriceFloatAmount(travelstandFlightVo.getLowpriceFloatAmount() == null ? "0"
                    : travelstandFlightVo.getLowpriceFloatAmount().toString());
            lowPriceDomAirTicket.setLowPriceFloatNum(travelstandFlightVo.getLowpriceFloatNum() == null ? "0"
                    : travelstandFlightVo.getLowpriceFloatNum().toString());
            flightTravelStandardManageVo.setLowPriceDomAirTicket(lowPriceDomAirTicket);
            //公里数管控
            MileageControl mileageControl = new MileageControl();
            mileageControl.setStatus(travelstandFlightVo.getMileageSwitch());
            mileageControl.setMileageNumber(travelstandFlightVo.getMileageMinMileageNumber());
            mileageControl.setMileageRcSet(travelstandFlightVo.getMileageControlType());
            mileageControl.setMileageRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.FM.getCode()));
            flightTravelStandardManageVo.setMileageControl(mileageControl);
            //提前预订
            AdvancedBook advancedBook = new AdvancedBook();
            advancedBook.setStatus(travelstandFlightVo.getAdvancedbookSwitch());
            advancedBook.setAdvancedBookDays(travelstandFlightVo.getAdvancedbookAdvancedDayNum());
            advancedBook.setBookRcSet(travelstandFlightVo.getAdvancedbookControlType());
            advancedBook.setBookRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.FA.getCode()));
            flightTravelStandardManageVo.setAdvancedBook(advancedBook);
            // 金额管控
            FlightAmountControlVo amountControlVo = new FlightAmountControlVo();
            amountControlVo.setStatus(travelstandFlightVo.getAmountControlSwitch());
            amountControlVo.setAmountControlNum(travelstandFlightVo.getAmountControlNum());
            amountControlVo.setAmountRcSet(travelstandFlightVo.getAmountControlType());
            amountControlVo.setAmountRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.AM.getCode()));
            flightTravelStandardManageVo.setAmountControlVo(amountControlVo);

            //时间管控
            TimeControl timeControl = new TimeControl();
            timeControl.setStatus(travelstandFlightVo.getTimeSwitch());
            timeControl.setTimeRcSet(travelstandFlightVo.getTimeControlType());
            timeControl.setTimeRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.FT.getCode()));
            timeControl.setMbTravelstandFlightTimeVos(travelstandFlightTimeVos);
            flightTravelStandardManageVo.setTimeControl(timeControl);
            //协议价管控
            ProtocolPriceControl protocolPriceControl = new ProtocolPriceControl();
            protocolPriceControl.setStatus(travelstandFlightVo.getProtocolPriceSwitch());
            protocolPriceControl.setProtocolPriceRcSet(travelstandFlightVo.getProtocolPriceControlType());
            protocolPriceControl.setProtocolPriceRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.FP.getCode()));
            flightTravelStandardManageVo.setProtocolPriceControl(protocolPriceControl);
            return flightTravelStandardManageVo;
        }
        return null;
    }

    /**
     * 将MbTravelstandIntlFlightVo转化为IntlFlightManageVo
     */
    public static IntlFlightManageVo travelstandIntlFlightVoToIntlFlightManageVo(MbTravelstandIntlFlightVo mbTravelstandIntlFlightVo,
          List<TravelStandardPostVo> travelStandardPostVos, List<MbTravelstandReasonCodeVo> reasonCodeVos,
           List<MbTravelstandFlightCabinVo> standFlightCabinVos,List<MbTravelstandIntlFlightTimeVo> travelstandFlightTimeVos) {
        if (mbTravelstandIntlFlightVo != null) {
            Map<String, List<Node>> dealReasonCodeVos = groupReasonCodeByType(reasonCodeVos);
            IntlFlightManageVo intlFlightManageVo = new IntlFlightManageVo();
            intlFlightManageVo.setOrgId(mbTravelstandIntlFlightVo.getOrgId());
            intlFlightManageVo.setTitle(mbTravelstandIntlFlightVo.getName());
            intlFlightManageVo.setId(String.valueOf(mbTravelstandIntlFlightVo.getId()));
            intlFlightManageVo.setProductSwitch(mbTravelstandIntlFlightVo.getProductSwitch());
            StringBuilder scopeIds = new StringBuilder("");
            if (travelStandardPostVos != null) {
                int i = 1;
                for (TravelStandardPostVo travelStandardPostVo : travelStandardPostVos) {
                    scopeIds.append(travelStandardPostVo.getPostid());
                    if (i < travelStandardPostVos.size()) {
                        scopeIds.append(",");
                    }
                    i++;
                }
            }
            intlFlightManageVo.setJobScopeId(scopeIds.toString());
            //设置舱等
            com.corpgovernment.api.travelstandard.vo.intlflight.ClassSpace classSpace = new com.corpgovernment.api.travelstandard.vo.intlflight.ClassSpace();
            classSpace.setStatus(mbTravelstandIntlFlightVo.getClassSwitch());
            if(StringUtils.isNotBlank(mbTravelstandIntlFlightVo.getClassClass())) {
                classSpace.setClassCheckList(IClazzEnum.getCheckedNodeByCode(mbTravelstandIntlFlightVo.getClassClass()));
            }
            classSpace.setClassRcSet(mbTravelstandIntlFlightVo.getClassControlType());
            classSpace.setClassRcList(dealReasonCodeVos.get(ReasonCodeTypeEnum.IFC.getCode()));
            if(CollectionUtils.isNotEmpty(standFlightCabinVos)) {
                List<com.corpgovernment.api.travelstandard.vo.intlflight.ClassSpace.ClassCheckNew>
                        classCheckNewList = new ArrayList<>();
                List<String> shieldedList = new ArrayList<>();
                for(MbTravelstandFlightCabinVo flightCabinVo:standFlightCabinVos) {
                    if(StringUtils.endsWithIgnoreCase(CommonConstant.T, flightCabinVo.getCabinType())) {
                        com.corpgovernment.api.travelstandard.vo.intlflight.ClassSpace.ClassCheckNew classCheckNew
                                = new com.corpgovernment.api.travelstandard.vo.intlflight.ClassSpace.ClassCheckNew();
                        classCheckNew.setClassCode(flightCabinVo.getClassCode());
                        classCheckNew.setClassName(IClazzEnum.getEnumByCode(flightCabinVo.getClassCode()).getName());
                        classCheckNew.setDurationType(flightCabinVo.getFlightDurationType());
                        classCheckNew.setDurationNum(flightCabinVo.getFlightDurationNum());
                        classCheckNewList.add(classCheckNew);
                    } else {
                        shieldedList.add(flightCabinVo.getClassCode());
                    }
                }
                classSpace.setClassCheckNewList(classCheckNewList);
                classSpace.setClassShieldedList(shieldedList);
            } else if(StringUtils.isNotBlank(mbTravelstandIntlFlightVo.getClassClass())) {
                List<com.corpgovernment.api.travelstandard.vo.intlflight.ClassSpace.ClassCheckNew>
                        classCheckNewList = new ArrayList<>();
                List<IClazzEnum> clazzEnums = IClazzEnum.getLowerClazzEnumThanCode(mbTravelstandIntlFlightVo.getClassClass());
                for (IClazzEnum clazzEnum : clazzEnums) {
                    com.corpgovernment.api.travelstandard.vo.intlflight.ClassSpace.ClassCheckNew classCheckNew
                            = new com.corpgovernment.api.travelstandard.vo.intlflight.ClassSpace.ClassCheckNew();
                    classCheckNew.setClassCode(clazzEnum.getCode());
                    classCheckNew.setClassName(clazzEnum.getName());
                    classCheckNew.setDurationType(CommonConstant.F);
                    classCheckNew.setDurationNum(0);
                    classCheckNewList.add(classCheckNew);
                }
                classSpace.setClassCheckNewList(classCheckNewList);
            }
            intlFlightManageVo.setClassSpace(classSpace);
            //低价管控
            LowPriceDomAirTicket lowPriceDomAirTicket = new LowPriceDomAirTicket();
            lowPriceDomAirTicket.setStatus(mbTravelstandIntlFlightVo.getLowpriceSwitch());
            if (mbTravelstandIntlFlightVo.getLowpriceTimeOption() != null) {
                lowPriceDomAirTicket.setLowPriceDomAirTicketTimeOptionsHour(String.valueOf(mbTravelstandIntlFlightVo.getLowpriceTimeOption() / 60));
                String lowPriceDomAirTicketTimeOptionsMinutes = new DecimalFormat("00").format(mbTravelstandIntlFlightVo.getLowpriceTimeOption() % 60);
                lowPriceDomAirTicket.setLowPriceDomAirTicketTimeOptionsMinutes(lowPriceDomAirTicketTimeOptionsMinutes);
            }
            lowPriceDomAirTicket.setLowPriceTimeStart(DateUtil.dateToHM(mbTravelstandIntlFlightVo.getLowpriceCompareTimeStart()));
            lowPriceDomAirTicket.setLowPriceTimeEnd(DateUtil.dateToHM(mbTravelstandIntlFlightVo.getLowpriceCompareTimeEnd()));
            lowPriceDomAirTicket.setLowPriceRcSet(mbTravelstandIntlFlightVo.getLowpriceControlType());
            lowPriceDomAirTicket.setAirportComparePrice(CommonConst.TRUE.equals(mbTravelstandIntlFlightVo.getAirportComparePrice()) ? CommonConst.TRUE : CommonConst.FALSE);
            lowPriceDomAirTicket.setLowPriceRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.IFL.getCode()));
            lowPriceDomAirTicket.setLowPriceFloatType(FlightSwitchEnum.LowPriceFloatTypeSwitch.B.getCode()
                    .equals(mbTravelstandIntlFlightVo.getLowpriceFloatType())
                    ? FlightSwitchEnum.LowPriceFloatTypeSwitch.B.getCode()
                    : FlightSwitchEnum.LowPriceFloatTypeSwitch.A.getCode());
            lowPriceDomAirTicket.setLowPriceFloatAmount(mbTravelstandIntlFlightVo.getLowpriceFloatAmount() == null ? "0"
                    : mbTravelstandIntlFlightVo.getLowpriceFloatAmount().toString());
            lowPriceDomAirTicket.setLowPriceFloatNum(mbTravelstandIntlFlightVo.getLowpriceFloatNum() == null ? "0"
                    : mbTravelstandIntlFlightVo.getLowpriceFloatNum().toString());
            intlFlightManageVo.setLowPriceDomAirTicket(lowPriceDomAirTicket);
            //提前预订
            AdvancedBook advancedBook = new AdvancedBook();
            advancedBook.setStatus(mbTravelstandIntlFlightVo.getAdvancedbookSwitch());
            advancedBook.setAdvancedBookDays(mbTravelstandIntlFlightVo.getAdvancedbookAdvancedDayNum());
            advancedBook.setBookRcSet(mbTravelstandIntlFlightVo.getAdvancedbookControlType());
            advancedBook.setBookRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.IFA.getCode()));
            intlFlightManageVo.setAdvancedBook(advancedBook);
            //时间管控
            TimeControl timeControl = new TimeControl();
            timeControl.setStatus(mbTravelstandIntlFlightVo.getTimeSwitch());
            timeControl.setTimeRcSet(mbTravelstandIntlFlightVo.getTimeControlType());
            timeControl.setTimeRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.IFT.getCode()));
            timeControl.setMbTravelstandIntlFlightTimeVos(travelstandFlightTimeVos);
            intlFlightManageVo.setTimeControl(timeControl);
            //协议价管控
            ProtocolPriceControl protocolPriceControl = new ProtocolPriceControl();
            protocolPriceControl.setStatus(mbTravelstandIntlFlightVo.getProtocolPriceSwitch());
            protocolPriceControl.setProtocolPriceRcSet(mbTravelstandIntlFlightVo.getProtocolPriceControlType());
            protocolPriceControl.setProtocolPriceRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.IFP.getCode()));
            intlFlightManageVo.setProtocolPriceControl(protocolPriceControl);

            // 金额管控
            IntlAmountControlVo amountControlVo = new IntlAmountControlVo();
            amountControlVo.setStatus(mbTravelstandIntlFlightVo.getAmountControlSwitch());
            amountControlVo.setAmountControlNum(mbTravelstandIntlFlightVo.getAmountControlNum());
            amountControlVo.setAmountControlCurrency(mbTravelstandIntlFlightVo.getAmountControlCurrency());

            CurrencyExchangeBO currencyExchangeBO = CurrencyConversionUtil.exchangeCurrency(
                    mbTravelstandIntlFlightVo.getAmountControlCurrency(), CommonConst.CNY_CODE,
                    new BigDecimal(mbTravelstandIntlFlightVo.getAmountControlNum()));
            if (!Objects.isNull(currencyExchangeBO)) {
                amountControlVo.setToCurrencyAmount(currencyExchangeBO.getToCurrencyAmount());
                amountControlVo.setExchangeToken(currencyExchangeBO.getExchangeToken());
            } else {
                log.error("汇率转换前币种为{}，金额为{}，汇率转换异常", mbTravelstandIntlFlightVo.getAmountControlCurrency(),
                        mbTravelstandIntlFlightVo.getAmountControlNum());
            }
            amountControlVo.setAmountRcSet(mbTravelstandIntlFlightVo.getAmountControlType());
            amountControlVo.setAmountRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.IAM.getCode()));
            intlFlightManageVo.setAmountControlVo(amountControlVo);


            return intlFlightManageVo;
        }
        return null;
    }

    /**
     * 将MbTravelstandFlightVo转化为FlightTravelStandardSoaVo
     *
     * @param travelstandFlightVo
     * @return
     */
    public static FlightTravelStandardSoaVo travelstandFlightVoToFlightTravelStandardSoaVo(
        MbTravelstandFlightVo travelstandFlightVo,
//            List<TravelStandardPostVo> travelStandardPostVos,
        List<MbTravelstandReasonCodeVo> reasonCodeVos,
        List<MbTravelstandFlightTimeVo> travelstandFlightTimeVos,
        List<MbTravelstandFlightCabinVo> standFlightCabinVos
    ) {
        if (travelstandFlightVo != null) {
            Map<String, List<Node>> dealReasonCodeVos = groupReasonCodeByType(reasonCodeVos);
            FlightTravelStandardSoaVo flightTravelStandardSoaVo = new FlightTravelStandardSoaVo();
            flightTravelStandardSoaVo.setOrgId(travelstandFlightVo.getOrgId());
            flightTravelStandardSoaVo.setTitle(travelstandFlightVo.getName());
            flightTravelStandardSoaVo.setId(String.valueOf(travelstandFlightVo.getId()));
            //设置舱等/折扣
            FlightTravelStandardSoaVo.ClassDiscountVo classDiscountVo = new FlightTravelStandardSoaVo.ClassDiscountVo();
            classDiscountVo.setClassDiscountChoose(travelstandFlightVo.getClassDiscountSwitch());
            classDiscountVo.setClassDiscountRcSet(travelstandFlightVo.getClassDiscountControlType());
            classDiscountVo.setClassDiscountRcList(dealReasonCodeVos.get(ReasonCodeTypeEnum.FC.getCode()));
            if(StringUtils.isNotBlank(travelstandFlightVo.getClassClass())) {
                classDiscountVo.setClassCode(travelstandFlightVo.getClassClass());
                classDiscountVo.setClassName(ClazzEnum.getEnumByCode(travelstandFlightVo.getClassClass()).getName());
            }
            if (FlightSwitchEnum.ClassDiscountSwitch.C.getCode().equals(travelstandFlightVo.getClassDiscountSwitch())) {
                if(CollectionUtils.isNotEmpty(standFlightCabinVos)) {
                    List<FlightTravelStandardSoaVo.ClassCheck> classCheckList = new ArrayList<>();
                    List<FlightTravelStandardSoaVo.ClassShielded> shieldedList = new ArrayList<>();
                    for(MbTravelstandFlightCabinVo flightCabinVo:standFlightCabinVos) {
                        if(StringUtils.endsWithIgnoreCase(CommonConstant.T, flightCabinVo.getCabinType())) {
                            FlightTravelStandardSoaVo.ClassCheck classCheckNew = new FlightTravelStandardSoaVo.ClassCheck();
                            classCheckNew.setClassCode(flightCabinVo.getClassCode());
                            classCheckNew.setClassName(ClazzEnum.getEnumByCode(flightCabinVo.getClassCode()).getName());
                            classCheckNew.setDurationType(flightCabinVo.getFlightDurationType());
                            classCheckNew.setDurationNum(flightCabinVo.getFlightDurationNum());
                            classCheckList.add(classCheckNew);
                        } else {
                            FlightTravelStandardSoaVo.ClassShielded shielded = new FlightTravelStandardSoaVo.ClassShielded();
                            shielded.setClassCode(flightCabinVo.getClassCode());
                            shielded.setClassName(ClazzEnum.getEnumByCode(flightCabinVo.getClassCode()).getName());
                            shieldedList.add(shielded);
                        }
                    }
                    classDiscountVo.setClassCheckList(classCheckList);
                    classDiscountVo.setClassShieldedList(shieldedList);
                } else if(StringUtils.isNotBlank(travelstandFlightVo.getClassClass())) {
                    List<FlightTravelStandardSoaVo.ClassCheck> classCheckList = new ArrayList<>();
                    List<ClazzEnum> clazzEnums = ClazzEnum.getLowerClazzEnumThanCode(travelstandFlightVo.getClassClass());
                    for (ClazzEnum clazzEnum : clazzEnums) {
                        FlightTravelStandardSoaVo.ClassCheck classCheckNew = new FlightTravelStandardSoaVo.ClassCheck();
                        classCheckNew.setClassCode(clazzEnum.getCode());
                        classCheckNew.setClassName(clazzEnum.getName());
                        classCheckNew.setDurationType(CommonConstant.F);
                        classCheckNew.setDurationNum(0);
                        classCheckList.add(classCheckNew);
                    }
                    classDiscountVo.setClassCheckList(classCheckList);
                }
            } else if (FlightSwitchEnum.ClassDiscountSwitch.D.getCode().equals(travelstandFlightVo.getClassDiscountSwitch())) {
                classDiscountVo.setClassCode(travelstandFlightVo.getDiscountClass());
                classDiscountVo.setClassName(ClazzEnum.getEnumByCode(travelstandFlightVo.getDiscountClass()).getName());
            }
            classDiscountVo.setDiscountNum(travelstandFlightVo.getDiscountNum());
            flightTravelStandardSoaVo.setClassDiscountVo(classDiscountVo);
            //设置低价
            FlightTravelStandardSoaVo.LowpriceVo lowpriceVo = new FlightTravelStandardSoaVo.LowpriceVo();
            lowpriceVo.setLowpriceSwitch(travelstandFlightVo.getLowpriceSwitch());
            lowpriceVo.setLowPriceDomAirTicketTimeOptionsHour(travelstandFlightVo.getLowpriceTimeOption() / 60);
            lowpriceVo.setLowPriceDomAirTicketTimeOptionsMinutes(travelstandFlightVo.getLowpriceTimeOption() % 60);
            lowpriceVo.setLowpriceCompareTimeStart(DateUtil.dateToString(travelstandFlightVo.getLowpriceCompareTimeStart(), DateUtil.DF_HM));
            lowpriceVo.setLowpriceCompareTimeEnd(DateUtil.dateToString(travelstandFlightVo.getLowpriceCompareTimeEnd(), DateUtil.DF_HM));
            lowpriceVo.setLowpriceControlType(travelstandFlightVo.getLowpriceControlType());
            lowpriceVo.setLowpriceVoRcList(dealReasonCodeVos.get(ReasonCodeTypeEnum.FL.getCode()));
            lowpriceVo.setAirportComparePrice(CommonConst.TRUE.equals(travelstandFlightVo.getAirportComparePrice()) ? CommonConst.TRUE : CommonConst.FALSE);
            lowpriceVo.setTransferNeedComparePrice(CommonConst.TRUE.equals(travelstandFlightVo.getLowpriceTransferNeedCompare()) ? CommonConst.TRUE : CommonConst.FALSE);
            lowpriceVo.setLowpriceFloatType(FlightSwitchEnum.LowPriceFloatTypeSwitch.B.getCode()
                    .equals(travelstandFlightVo.getLowpriceFloatType())
                    ? FlightSwitchEnum.LowPriceFloatTypeSwitch.B.getCode()
                    : FlightSwitchEnum.LowPriceFloatTypeSwitch.A.getCode());
            lowpriceVo.setLowpriceFloatAmount(travelstandFlightVo.getLowpriceFloatAmount());
            lowpriceVo.setLowpriceFloatNum(travelstandFlightVo.getLowpriceFloatNum());
            flightTravelStandardSoaVo.setLowpriceVo(lowpriceVo);
            //设置公里数管控
            FlightTravelStandardSoaVo.MileageVo mileageVo = new FlightTravelStandardSoaVo.MileageVo();
            mileageVo.setStatus(travelstandFlightVo.getMileageSwitch());
            mileageVo.setMileageNumber(travelstandFlightVo.getMileageMinMileageNumber());
            mileageVo.setMileageRcSet(travelstandFlightVo.getMileageControlType());
            mileageVo.setMileageRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.FM.getCode()));
            flightTravelStandardSoaVo.setMileageVo(mileageVo);
            //设置提前预订管控
            FlightTravelStandardSoaVo.AdvancedBookVo advancedBookVo = new FlightTravelStandardSoaVo.AdvancedBookVo();
            advancedBookVo.setStatus(travelstandFlightVo.getAdvancedbookSwitch());
            advancedBookVo.setAdvancedBookDays(travelstandFlightVo.getAdvancedbookAdvancedDayNum());
            advancedBookVo.setBookRcSet(travelstandFlightVo.getAdvancedbookControlType());
            advancedBookVo.setBookRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.FA.getCode()));
            flightTravelStandardSoaVo.setAdvancedBookVo(advancedBookVo);
            //设置金额管控
            FlightTravelStandardSoaVo.FlightAmountControlVo amountControlVo = new FlightTravelStandardSoaVo.FlightAmountControlVo();
            amountControlVo.setStatus(travelstandFlightVo.getAmountControlSwitch());
            amountControlVo.setAmountControlNum(travelstandFlightVo.getAmountControlNum());
            amountControlVo.setAmountRcSet(travelstandFlightVo.getAmountControlType());
            amountControlVo.setAmountRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.AM.getCode()));
            flightTravelStandardSoaVo.setAmountControlVo(amountControlVo);
            //设置时间管控
            FlightTravelStandardSoaVo.TimeVo timeVo = new FlightTravelStandardSoaVo.TimeVo();
            timeVo.setStatus(travelstandFlightVo.getTimeSwitch());
            timeVo.setMbTravelstandFlightTimeVos(travelstandFlightTimeVos);
            timeVo.setTimeRcSet(travelstandFlightVo.getTimeControlType());
            timeVo.setTimeRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.FT.getCode()));
            flightTravelStandardSoaVo.setTimeVo(timeVo);
            //设置协议价管控
            ProtocolPriceControl protocolPriceControl = new ProtocolPriceControl();
            protocolPriceControl.setStatus(travelstandFlightVo.getProtocolPriceSwitch());
            protocolPriceControl.setProtocolPriceRcSet(travelstandFlightVo.getProtocolPriceControlType());
            protocolPriceControl.setProtocolPriceRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.FP.getCode()));
            flightTravelStandardSoaVo.setProtocolPrice(protocolPriceControl);
            return flightTravelStandardSoaVo;
        }
        return null;
    }

    /**
     * 将travelstandTrainVo转化为TrainTravelStandardManageVo
     *
     * @param travelstandTrainVo      后端对象
     * @param travelStandardPostVos   岗位列表
     * @param reasonCodeVos           rc列表
     * @param travelstandTrainSeatVos 已选坐席
     * @return
     */
    public static TrainTravelStandardManageVo travelstandTrainVoToTrainTravelStandardManageVo(
        MbTravelstandTrainVo travelstandTrainVo,
        List<TravelStandardPostVo> travelStandardPostVos,
        List<MbTravelstandReasonCodeVo> reasonCodeVos,
        List<MbTravelstandTrainSeatVo> travelstandTrainSeatVos
    ) {
        if (travelstandTrainVo != null) {
            Map<String, List<Node>> dealReasonCodeVos = groupReasonCodeByType(reasonCodeVos);
            TrainTravelStandardManageVo trainTravelStandardManageVo = new TrainTravelStandardManageVo();
            trainTravelStandardManageVo.setOrgId(travelstandTrainVo.getOrgId());
            trainTravelStandardManageVo.setTitle(travelstandTrainVo.getName());
            trainTravelStandardManageVo.setId(String.valueOf(travelstandTrainVo.getId()));
            trainTravelStandardManageVo.setProductSwitch(travelstandTrainVo.getProductSwitch());
            StringBuilder scopeIds = new StringBuilder("");
            if (travelStandardPostVos != null) {
                int i = 1;
                for (TravelStandardPostVo travelStandardPostVo : travelStandardPostVos) {
                    scopeIds.append(travelStandardPostVo.getPostid());
                    if (i < travelStandardPostVos.size()) {
                        scopeIds.append(",");
                    }
                    i++;
                }
            }
            trainTravelStandardManageVo.setJobScopeId(scopeIds.toString());
            //坐席控制
            SeatControl seatControl = new SeatControl();
            seatControl.setSeatRcList(dealReasonCodeVos.get(ReasonCodeTypeEnum.TS.getCode()));
            seatControl.setSeatAvailabeList(TrainSeatEnum.getCheckedNodeByCode(travelstandTrainSeatVos));
            seatControl.setSeatRcSet(travelstandTrainVo.getControlType());
            seatControl.setStatus(travelstandTrainVo.getSeatSwitch());
            seatControl.setStcStatus(travelstandTrainVo.getStcStatus());
            seatControl.setStcControlType(travelstandTrainVo.getStcControlType());
            seatControl.setSubstituteTicketTrainNumber(travelstandTrainVo.getSubstituteTicketTrainNumber());

            trainTravelStandardManageVo.setSeatControl(seatControl);
            return trainTravelStandardManageVo;
        }
        return null;
    }

    /**
     * 将MbTravelstandCarVo转化为CarManagelVo
     */
    public static CarManageVo travelstandCarVoToCarManageVo(
        MbTravelstandCarVo mbTravelstandCarVo,
        List<TravelStandardPostVo> travelStandardPostVos,
        List<MbTravelstandReasonCodeVo> reasonCodeVos,
        List<MbTravelstandCarModelVo> mbTravelstandCarModelVos,
        List<MbTravelstandCarDatetime> mbTravelstandCarDatetimes,
        List<MbTravelStandCarCity> mbTravelStandCarCities,
        List<MbTravelStandCarAddress> mbTravelStandCarAddresses,
        List<MbTravelStandCarCrossCity> mbTravelStandCarCrossCities,
        MbTravelStandCarTimes mbTravelStandCarTimes
    ) {
        if (mbTravelstandCarVo != null) {
            Map<String, List<Node>> dealReasonCodeVos = groupReasonCodeByType(reasonCodeVos);
            CarManageVo carManageVo = new CarManageVo();
            carManageVo.setOrgId(mbTravelstandCarVo.getOrgId());
            carManageVo.setTitle(mbTravelstandCarVo.getName());
            carManageVo.setId(String.valueOf(mbTravelstandCarVo.getId()));
            carManageVo.setSceneCode(mbTravelstandCarVo.getSceneCode());
            carManageVo.setSceneName(mbTravelstandCarVo.getSceneName());
            carManageVo.setProductSwitch(mbTravelstandCarVo.getProductSwitch());
            StringBuilder scopeIds = new StringBuilder("");
            if (travelStandardPostVos != null) {
                int i = 1;
                for (TravelStandardPostVo travelStandardPostVo : travelStandardPostVos) {
                    scopeIds.append(travelStandardPostVo.getPostid());
                    if (i < travelStandardPostVos.size()) {
                        scopeIds.append(",");
                    }
                    i++;
                }
            }
            carManageVo.setJobScopeId(scopeIds.toString());
            //价格控制
            PriceControl priceControl = new PriceControl();
            priceControl.setStatus(mbTravelstandCarVo.getPriceSwitch());
            priceControl.setPriceCeiling(mbTravelstandCarVo.getPriceUpperLimit());
            priceControl.setDayPriceCeiling(mbTravelstandCarVo.getDayPriceUpper());
            priceControl.setMonthPriceCeiling(mbTravelstandCarVo.getMonthPriceUpper());
            priceControl.setPriceRcSet(mbTravelstandCarVo.getPriceControlType());
            priceControl.setPriceRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.CP.getCode()));
            carManageVo.setPriceControl(priceControl);
            //车型控制
            ModelControl modelControl = new ModelControl();
            modelControl.setStatus(mbTravelstandCarVo.getModelSwitch());
            modelControl.setCarTypeList(CarModelEnum.getCheckedNodeByCode(mbTravelstandCarModelVos));
            modelControl.setModelRcSet(mbTravelstandCarVo.getModelControlType());
            modelControl.setModelRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.CM.getCode()));
            carManageVo.setModelControl(modelControl);
            //用车时间控制
            DatetimeControl datetimeControl = new DatetimeControl();
            datetimeControl.setStatus(mbTravelstandCarVo.getDatetimeSwitch());
            datetimeControl.setDatetimeRcSet(mbTravelstandCarVo.getDatetimeControlType());
            datetimeControl.setDatetimeRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.CD.getCode()));
            List<CarDatetimeVo> datetimeVos = new ArrayList<>();
            for (int i = 0; i <mbTravelstandCarDatetimes.size() ; i++) {
                MbTravelstandCarDatetime item = mbTravelstandCarDatetimes.get(i);
                CarDatetimeVo target = new CarDatetimeVo();
                target.setTsid(item.getTsid());
                target.setIsWork(item.getIsWork());
                target.setStartTime(item.getStartTime());
                target.setEndTime(item.getEndTime());
                target.setStatus(item.getStatus());
                target.setIsNextDay(item.getIsNextDay());
                TimesVo _times = new TimesVo();
                if(ObjectUtil.isNull(item.getStartTime()) || ObjectUtil.isNull(item.getEndTime())){
                    continue;
                }
                String[] startParts = item.getStartTime().split(":");
                String[] endParts = item.getEndTime().split(":");
                if(startParts.length >= 2 && endParts.length >= 2){
                    _times.setStartHour(startParts[0]);
                    _times.setStartMin(startParts[1]);
                    _times.setEndHour(addZeroForStr(String.valueOf(Integer.parseInt(endParts[0])+ 24* item.getIsNextDay()),2,1));
                    _times.setEndMin(endParts[1]);
                    target.set_times(_times);
                }
                datetimeVos.add(target);
            }
            datetimeControl.setCarDatetimes(datetimeVos);
            carManageVo.setDatetimeControl(datetimeControl);
            //用车城市控制
            CarCityControl carCityControl = new CarCityControl();
            carCityControl.setStatus(mbTravelstandCarVo.getCarCitySwitch());
            carCityControl.setCarCityRcSet(mbTravelstandCarVo.getCarCityControlType());
            carCityControl.setCarCityRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.CC.getCode()));
            carCityControl.setTsid(CollectionUtils.isEmpty(mbTravelStandCarCities) ? null : mbTravelStandCarCities.get(0).getTsid());
            CarCityControlVo carCityControlVo = new CarCityControlVo();
            carCityControlVo.setControlType(CollectionUtils.isEmpty(mbTravelStandCarCities) ? null : mbTravelStandCarCities.get(0).getControlType());
            List<CarCityVo> cityVos = new ArrayList<>();
            Optional.ofNullable(mbTravelStandCarCities).orElse(new ArrayList<>()).stream().forEach(item -> cityVos.add(new CarCityVo(item.getCityName(), item.getCityCode())));
            carCityControlVo.setCityVos(cityVos);
            carCityControl.setCarCityControlVo(carCityControlVo);
            //用车城市控制[跨城]
            CarCrossCityControlVo carCrossCityControlVo = new CarCrossCityControlVo();
            carCrossCityControlVo.setControlType(CollectionUtils.isEmpty(mbTravelStandCarCrossCities) ? null : mbTravelStandCarCrossCities.get(0).getControlType());
            List<CarCrossCityVo> cityVoPairs = new ArrayList<>();
            Optional.ofNullable(mbTravelStandCarCrossCities).orElse(new ArrayList<>()).stream().forEach(item -> cityVoPairs.add(new CarCrossCityVo(new CarCityVo(item.getLeftCityName(), item.getLeftCityCode()),new CarCityVo(item.getRightCityName(), item.getRightCityCode()))));
            carCrossCityControlVo.setCrossCityVos(cityVoPairs);
            carCityControl.setCrossCityControlVo(carCrossCityControlVo);
            carManageVo.setCarCityControl(carCityControl);
            //用车地点控制
            CarAddressControl carAddressControl = new CarAddressControl();
            carAddressControl.setStatus(mbTravelstandCarVo.getCarAddressSwitch());
            carAddressControl.setCarAddressRcSet(mbTravelstandCarVo.getCarAddressControlType());
            carAddressControl.setCarAddressRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.CA.getCode()));
            carAddressControl.setTsid(CollectionUtils.isEmpty(mbTravelStandCarAddresses) ? null : mbTravelStandCarAddresses.get(0).getTsid());
            List<CarAddressVo> carAddresses = new ArrayList<>();
            Optional.ofNullable(mbTravelStandCarAddresses).orElse(new ArrayList<>()).stream().forEach(item -> carAddresses.add(new CarAddressVo(item.getCityName(), item.getCityCode(), item.getAddress(), item.getAddressDetail(), item.getLatitude(), item.getLongitude(), item.getCarRange())));
            carAddressControl.setCarAddresses(carAddresses);
            carAddressControl.setAddressControlType(CollectionUtils.isEmpty(mbTravelStandCarAddresses) ? 0 : mbTravelStandCarAddresses.get(0).getAddressControlType());
            carManageVo.setCarAddressControl(carAddressControl);

            CarTimesControl carTimesControl = new CarTimesControl();
            carTimesControl.setStatus(mbTravelstandCarVo.getCarTimesSwitch());
            carTimesControl.setCarTimeRCSet(mbTravelstandCarVo.getCarTimesControlType());
            carTimesControl.setCarTimesRCCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.CT.getCode()));
            //用车次数控制
            if(ObjectUtil.isNotNull(mbTravelStandCarTimes)){
                carTimesControl.setDayTimesCeiling(mbTravelStandCarTimes.getDayTimes());
                carTimesControl.setMonthTimesCeiling(mbTravelStandCarTimes.getMonthTimes());
            }
            carManageVo.setCarTimesControl(carTimesControl);

            return carManageVo;
        }
        return null;
    }

    public static String addZeroForStr(String str, int length,int type) {
        int strLen = str.length();
        if (strLen < length) {
            while (strLen < length) {
                StringBuffer sb = new StringBuffer();
                if(type==1){
                    // 左补0
                    sb.append("0").append(str);
                }else if(type==2){
                    //右补0
                    sb.append(str).append("0");
                }
                str = sb.toString();
                strLen = str.length();
            }
        }
        return str;
    }

    /**
     * 将MbTravelstandCarVo转化为CarManageSoaVo
     */
    public static CarManageSoaVo travelstandCarVoToCarManageSoaVo(
        MbTravelstandCarVo mbTravelstandCarVo,
        List<TravelStandardPostVo> travelStandardPostVos,
        List<MbTravelstandReasonCodeVo> reasonCodeVos,
        List<MbTravelstandCarModelVo> mbTravelstandCarModelVos,
        List<MbTravelstandCarDatetime> mbTravelstandCarDatetimes,
        List<MbTravelStandCarCity> mbTravelStandCarCities,
        List<MbTravelStandCarAddress> mbTravelStandCarAddresses,
        List<MbTravelStandCarCrossCity> mbTravelStandCarCrossCities,
        MbTravelStandCarTimes mbTravelStandCarTimes
    ) {
        if (mbTravelstandCarVo != null) {
            Map<String, List<Node>> dealReasonCodeVos = groupReasonCodeByType(reasonCodeVos);
            CarManageSoaVo carManageSoaVo = new CarManageSoaVo();
            carManageSoaVo.setOrgId(mbTravelstandCarVo.getOrgId());
            carManageSoaVo.setTitle(mbTravelstandCarVo.getName());
            carManageSoaVo.setId(String.valueOf(mbTravelstandCarVo.getId()));
            StringBuilder scopeIds = new StringBuilder("");
            if (travelStandardPostVos != null) {
                int i = 1;
                for (TravelStandardPostVo travelStandardPostVo : travelStandardPostVos) {
                    scopeIds.append(travelStandardPostVo.getPostid());
                    if (i < travelStandardPostVos.size()) {
                        scopeIds.append(",");
                    }
                    i++;
                }
            }
            carManageSoaVo.setJobScopeId(scopeIds.toString());
            carManageSoaVo.setSceneCode(mbTravelstandCarVo.getSceneCode());
            carManageSoaVo.setSceneName(mbTravelstandCarVo.getSceneName());
            //价格控制
            PriceControl priceControl = new PriceControl();
            priceControl.setStatus(mbTravelstandCarVo.getPriceSwitch());
            priceControl.setPriceCeiling(mbTravelstandCarVo.getPriceUpperLimit());
            priceControl.setDayPriceCeiling(mbTravelstandCarVo.getDayPriceUpper());
            priceControl.setMonthPriceCeiling(mbTravelstandCarVo.getMonthPriceUpper());
            priceControl.setPriceRcSet(mbTravelstandCarVo.getPriceControlType());
            priceControl.setPriceRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.CP.getCode()));
            carManageSoaVo.setPriceControl(priceControl);
            //车型控制
            ModelControl modelControl = new ModelControl();
            modelControl.setStatus(mbTravelstandCarVo.getModelSwitch());
            modelControl.setCarTypeList(CarModelEnum.getCheckedNodeByCode(mbTravelstandCarModelVos));
            modelControl.setModelRcSet(mbTravelstandCarVo.getModelControlType());
            modelControl.setModelRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.CM.getCode()));
            carManageSoaVo.setModelControl(modelControl);
            //用车时间控制
            DatetimeControl datetimeControl = new DatetimeControl();
            datetimeControl.setStatus(mbTravelstandCarVo.getDatetimeSwitch());
            datetimeControl.setDatetimeRcSet(mbTravelstandCarVo.getDatetimeControlType());
            datetimeControl.setDatetimeRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.CD.getCode()));
            List<CarDatetimeVo> datetimeVos = new ArrayList<>();
            for (int i = 0; i <mbTravelstandCarDatetimes.size() ; i++) {
                MbTravelstandCarDatetime item = mbTravelstandCarDatetimes.get(i);
                CarDatetimeVo target = new CarDatetimeVo();
                target.setTsid(item.getTsid());
                target.setIsWork(item.getIsWork());
                target.setStartTime(item.getStartTime());
                target.setEndTime(item.getEndTime());
                target.setStatus(item.getStatus());
                target.setIsNextDay(item.getIsNextDay());
                TimesVo _times = new TimesVo();
                String[] startParts = item.getStartTime().split(":");
                String[] endParts = item.getEndTime().split(":");
                _times.setStartHour(startParts[0]);
                _times.setStartMin(startParts[1]);
                _times.setEndHour(String.valueOf(Integer.parseInt(endParts[0])+ 24* item.getIsNextDay()));
                _times.setEndMin(endParts[1]);
                target.set_times(_times);
                datetimeVos.add(target);
            }
            datetimeControl.setCarDatetimes(datetimeVos);
            carManageSoaVo.setDatetimeControl(datetimeControl);
//            //用车城市控制
            CarCityControl carCityControl = new CarCityControl();
            carCityControl.setStatus(mbTravelstandCarVo.getCarCitySwitch());
            carCityControl.setCarCityRcSet(mbTravelstandCarVo.getCarCityControlType());
            carCityControl.setCarCityRcCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.CC.getCode()));
            CarCityControlVo carCityControlVo = new CarCityControlVo();
            carCityControlVo.setControlType((byte)0);
            List<CarCityVo> cityVos = new ArrayList<>();
            Optional.ofNullable(mbTravelStandCarCities).orElse(new ArrayList<>()).stream().forEach(item -> cityVos.add(new CarCityVo(item.getCityName(), item.getCityCode())));
            carCityControlVo.setCityVos(cityVos);
            carCityControl.setCarCityControlVo(carCityControlVo);
            carCityControl.setTsid(mbTravelstandCarVo.getId());
            carManageSoaVo.setCarCityControl(carCityControl);

            //用车城市控制[跨城]
            CarCrossCityControlVo carCrossCityControlVo = new CarCrossCityControlVo();
            carCrossCityControlVo.setControlType(CollectionUtils.isEmpty(mbTravelStandCarCrossCities) ? null : mbTravelStandCarCrossCities.get(0).getControlType());
            List<CarCrossCityVo> cityVoPairs = new ArrayList<>();
            Optional.ofNullable(mbTravelStandCarCrossCities).orElse(new ArrayList<>()).stream().forEach(item -> cityVoPairs.add(new CarCrossCityVo(new CarCityVo(item.getLeftCityName(), item.getLeftCityCode()),new CarCityVo(item.getRightCityName(), item.getRightCityCode()))));
            carCrossCityControlVo.setCrossCityVos(cityVoPairs);
            carCityControl.setCrossCityControlVo(carCrossCityControlVo);
            carManageSoaVo.setCarCityControl(carCityControl);

            //用车地点控制
            CarAddressControl carAddressControl = new CarAddressControl();
            carAddressControl.setStatus(mbTravelstandCarVo.getCarAddressSwitch());
            carAddressControl.setCarAddressRcSet(mbTravelstandCarVo.getCarAddressControlType());
            carAddressControl.setCarAddressRcCheckList((dealReasonCodeVos.get(ReasonCodeTypeEnum.CA.getCode())));
            carAddressControl.setTsid(mbTravelstandCarVo.getId());
            List<CarAddressVo> carAddresses = new ArrayList<>();
            Optional.ofNullable(mbTravelStandCarAddresses).orElse(new ArrayList<>()).forEach(item -> carAddresses.add(new CarAddressVo(item.getCityName(), item.getCityCode(), item.getAddress(), item.getAddressDetail(), item.getLatitude(), item.getLongitude(), item.getCarRange())));
            carAddressControl.setCarAddresses(carAddresses);
            carAddressControl.setAddressControlType((byte)0);
            carManageSoaVo.setCarAddressControl(carAddressControl);

            //用车次数控制
            if(ObjectUtil.isNotNull(mbTravelStandCarTimes)){
                CarTimesControl carTimesControl = new CarTimesControl();
                carTimesControl.setStatus(mbTravelstandCarVo.getCarTimesSwitch());
                carTimesControl.setDayTimesCeiling(mbTravelStandCarTimes.getDayTimes());
                carTimesControl.setMonthTimesCeiling(mbTravelStandCarTimes.getMonthTimes());
                carTimesControl.setCarTimeRCSet(mbTravelstandCarVo.getCarTimesControlType());
                carTimesControl.setCarTimesRCCheckList(dealReasonCodeVos.get(ReasonCodeTypeEnum.CT.getCode()));
                carManageSoaVo.setCarTimesControl(carTimesControl);
            }
            return carManageSoaVo;
        }
        return null;
    }

    /**
     * 将TravelstandHotelVo转换为HotelTravelStandardManageVo
     *
     * @param travelstandHotelVo       后端对象
     * @param travelStandardPostVos    岗位列表
     * @param reasonCodeVos            rc列表
     * @param travelstandHotelPriceVos 区域限价
     * @return
     */
    public static HotelTravelStandardManageVo travelstandHotelVoToHotelTravelStandardManageVo(
        MbTravelstandHotelVo travelstandHotelVo,
        List<TravelStandardPostVo> travelStandardPostVos,
        List<MbTravelstandReasonCodeVo> reasonCodeVos,
        List<MbTravelstandHotelPriceVo> travelstandHotelPriceVos,
        List<MbTravelstandHotelQuarterVo> travelstandHotelQuarterVos
    ) {
        if (travelstandHotelVo != null) {
            Map<String, List<Node>> dealReasonCodeVos = groupReasonCodeByType(reasonCodeVos);
            HotelTravelStandardManageVo travelStandardManageVo = new HotelTravelStandardManageVo();
            travelStandardManageVo.setId(String.valueOf(travelstandHotelVo.getId()));
            travelStandardManageVo.setTitle(travelstandHotelVo.getName());
            travelStandardManageVo.setOrgId(travelstandHotelVo.getOrgId());
            travelStandardManageVo.setHotelProductSwitch(travelstandHotelVo.getHotelProductSwitch());
            travelStandardManageVo.setHotelIntlProductSwitch(travelstandHotelVo.getHotelIntlProductSwitch());
            StringBuilder scopeIds = new StringBuilder("");
            if (travelStandardPostVos != null) {
                int i = 1;
                for (TravelStandardPostVo travelStandardPostVo : travelStandardPostVos) {
                    scopeIds.append(travelStandardPostVo.getPostid());
                    if (i < travelStandardPostVos.size()) {
                        scopeIds.append(",");
                    }
                    i++;
                }
            }
            travelStandardManageVo.setJobScopeId(scopeIds.toString());
            //价格控制
            HotelPriceControl hotelPriceControl = new HotelPriceControl();
            hotelPriceControl.setHotelPriceRcList(dealReasonCodeVos.get(ReasonCodeTypeEnum.HP.getCode()));
            hotelPriceControl.setHotelPriceRcSet(travelstandHotelVo.getControlType());
            hotelPriceControl.setStatus(travelstandHotelVo.getPriceSwitch());
            hotelPriceControl.setHotelPrices(travelstandHotelPriceVos);
            hotelPriceControl.setIntlStatus(travelstandHotelVo.getPriceSwitchIntl());
            hotelPriceControl.setSharedManageStatus(travelstandHotelVo.getSharedManageStatus());
            hotelPriceControl.setHotelManageRules(travelstandHotelVo.getHotelManageRules());
            hotelPriceControl.setSharedPercentage(travelstandHotelVo.getSharedPercentage());

            hotelPriceControl.setHotelManageStrategy(travelstandHotelVo.getHotelManageStrategy());
            hotelPriceControl.setPriceFloatSwitch(travelstandHotelVo.getPriceFloatSwitch());
            hotelPriceControl.setFloatControlType(travelstandHotelVo.getFloatControlType());
            hotelPriceControl.setFloatQuarterSwitch(travelstandHotelVo.getFloatQuarterSwitch());
            hotelPriceControl.setPriceFloatSwitchIntl(travelstandHotelVo.getPriceFloatSwitchIntl());
            //淡旺季控制
            HotelQuarterControl hotelQuarterControl = new HotelQuarterControl();
            hotelQuarterControl.setStatus(travelstandHotelVo.getQuarterSwitch());
            hotelQuarterControl.setQuarterInfos(getQuarterInfo(travelstandHotelQuarterVos));
            hotelPriceControl.setHotelQuarterControl(hotelQuarterControl);
            travelStandardManageVo.setHotelPriceControl(hotelPriceControl);
            return travelStandardManageVo;
        }
        return null;
    }


    /**
     * 将travelstandTrainVo转化为TrainTravelStandardSoaVo
     *
     * @param travelstandTrainVo      后端对象
     * @param reasonCodeVos           rc列表
     * @param travelstandTrainSeatVos 已选坐席
     * @return
     */
    public static TrainTravelStandardSoaVo travelstandTrainVoToTrainTravelStandardSoaVo(
        MbTravelstandTrainVo travelstandTrainVo,
        List<TravelStandardPostVo> travelStandardPostVos,
        List<MbTravelstandReasonCodeVo> reasonCodeVos,
        List<MbTravelstandTrainSeatVo> travelstandTrainSeatVos
    ) {
        if (travelstandTrainVo != null) {
            Map<String, List<Node>> dealReasonCodeVos = groupReasonCodeByType(reasonCodeVos);
            TrainTravelStandardSoaVo trainTravelStandardSoaVo = new TrainTravelStandardSoaVo();
            trainTravelStandardSoaVo.setOrgId(travelstandTrainVo.getOrgId());
            trainTravelStandardSoaVo.setTitle(travelstandTrainVo.getName());
            trainTravelStandardSoaVo.setId(String.valueOf(travelstandTrainVo.getId()));
            trainTravelStandardSoaVo.setProductSwitch(travelstandTrainVo.getProductSwitch());
            StringBuilder scopeIds = new StringBuilder("");
            if (travelStandardPostVos != null) {
                for (TravelStandardPostVo travelStandardPostVo : travelStandardPostVos) {
                    scopeIds.append(travelStandardPostVo.getId());
                    scopeIds.append(",");
                }
            }
            trainTravelStandardSoaVo.setJobScopeId(scopeIds.toString());
            //坐席控制
            TrainTravelStandardSoaVo.SeatVo seatVo = new TrainTravelStandardSoaVo.SeatVo();
            seatVo.setSeatRcList(dealReasonCodeVos.get(ReasonCodeTypeEnum.TS.getCode()));
            seatVo.setSeatAvailabeList(TrainSeatEnum.getCheckedNodeByCode(travelstandTrainSeatVos));
            seatVo.setSeatRcSet(travelstandTrainVo.getControlType());
            seatVo.setStatus(travelstandTrainVo.getSeatSwitch());
            seatVo.setStcStatus(travelstandTrainVo.getStcStatus());
            seatVo.setStcControlType(travelstandTrainVo.getStcControlType());
            seatVo.setSubstituteTicketTrainNumber(travelstandTrainVo.getSubstituteTicketTrainNumber());

            trainTravelStandardSoaVo.setSeatVo(seatVo);
            return trainTravelStandardSoaVo;
        }
        return null;
    }

    /**
     * 对rc根据type进行分组，并转换为node
     *
     * @param reasonCodeVos
     * @return
     */
    public static Map<String, List<Node>> groupReasonCodeByType(List<MbTravelstandReasonCodeVo> reasonCodeVos) {
        Map<String, List<Node>> datas = new HashMap<>();
        for (ReasonCodeTypeEnum reasonCodeTypeEnum : ReasonCodeTypeEnum.values()) {
            List<Node> nodes = new ArrayList<>();
            for (MbTravelstandReasonCodeVo travelstandReasonCodeVo : reasonCodeVos) {
                if (travelstandReasonCodeVo.getTsRcType().equals(reasonCodeTypeEnum.getCode())) {
                    Node node = new Node();
                    node.setIsChecked(travelstandReasonCodeVo.getIsChecked());
                    node.setName(travelstandReasonCodeVo.getName());
                    node.setId(String.valueOf(travelstandReasonCodeVo.getId()));
                    node.setCode(reasonCodeTypeEnum.getCode());
                    nodes.add(node);
                }
            }
            datas.put(reasonCodeTypeEnum.getCode(), nodes);
        }
        return datas;
    }

    public static Map<String, List<Node>> groupReasonCodeByTypeNew(List<MbTravelstandReasonCode> reasonCode) {
        Map<String, List<Node>> datas = new HashMap<>();
        for (ReasonCodeTypeEnum reasonCodeTypeEnum : ReasonCodeTypeEnum.values()) {
            List<Node> nodes = new ArrayList<>();
            for (MbTravelstandReasonCode travelstandReasonCode : reasonCode) {
                if (travelstandReasonCode.getTsRcType().equals(reasonCodeTypeEnum.getCode())) {
                    Node node = new Node();
                    node.setIsChecked(travelstandReasonCode.getIsChecked());
                    node.setName(travelstandReasonCode.getName());
                    node.setId(String.valueOf(travelstandReasonCode.getId()));
                    node.setCode(reasonCodeTypeEnum.getCode());
                    nodes.add(node);
                }
            }
            datas.put(reasonCodeTypeEnum.getCode(), nodes);
        }
        return datas;
    }

    public static List<HotelQuarterControl.QuarterInfo> getQuarterInfo(List<MbTravelstandHotelQuarterVo> mbTravelstandHotelQuarterVos) {
        if (mbTravelstandHotelQuarterVos != null) {
            Map<Long, AreaConfigVo> areaConfigVoMap = new LinkedHashMap<>();
            Map<Long, List<MbTravelstandHotelQuarterVo>> mbTravelstandHotelQuarterVoMap = new HashMap<>();
            for (MbTravelstandHotelQuarterVo mbTravelstandHotelQuarterVo : mbTravelstandHotelQuarterVos) {
                Long tsHotelAreaId = mbTravelstandHotelQuarterVo.getTsHotelAreaId();
                //获得区域信息
                if (areaConfigVoMap.get(tsHotelAreaId) == null) {
                    AreaConfigVo areaConfigVo = new AreaConfigVo()
                        .setAreaName(mbTravelstandHotelQuarterVo.getAreaName())
                        .setAreaType(mbTravelstandHotelQuarterVo.getAreaType())
                        .setId(tsHotelAreaId)
                        .setHotelType(mbTravelstandHotelQuarterVo.getHotelType());
                    areaConfigVoMap.put(tsHotelAreaId, areaConfigVo);
                }
                //根据归类淡旺季限价信息
                if (mbTravelstandHotelQuarterVoMap.get(tsHotelAreaId) == null) {
                    List<MbTravelstandHotelQuarterVo> mapData = new ArrayList<>();
                    mapData.add(mbTravelstandHotelQuarterVo);
                    mbTravelstandHotelQuarterVoMap.put(tsHotelAreaId, mapData);
                } else {
                    mbTravelstandHotelQuarterVoMap.get(tsHotelAreaId).add(mbTravelstandHotelQuarterVo);
                }
            }
            List<HotelQuarterControl.QuarterInfo> quarterInfos = new ArrayList<>();
            //对区域进行排序，将其它区域排在最后一个
            for (Long key : areaConfigVoMap.keySet()) {
                AreaConfigVo areaConfigVo = areaConfigVoMap.get(key);
                if (AreaTypeEnum.TYPE_1.getCode().equals(areaConfigVo.getAreaType())) {
                    areaConfigVoMap.remove(key);
                    areaConfigVoMap.put(key, areaConfigVo);
                    break;
                }
            }
            //生成淡旺季对象
            for (Long key : areaConfigVoMap.keySet()) {
                AreaConfigVo areaConfigVo = areaConfigVoMap.get(key);
                HotelQuarterControl.QuarterInfo quarterInfo = new HotelQuarterControl.QuarterInfo();
                quarterInfo.setAreaName(areaConfigVo.getAreaName());
                quarterInfo.setTsHotelAreaId(areaConfigVo.getId());
                quarterInfo.setHotelQuarterVos(mbTravelstandHotelQuarterVoMap.get(key));
                quarterInfo.setHotelType(areaConfigVo.getHotelType());
                quarterInfos.add(quarterInfo);
            }
            return quarterInfos;
        }
        return null;
    }

}
